package com.macro.mall.controller;


import com.macro.mall.common.api.CommonResult;
import com.macro.mall.entity.Transfer;
import com.macro.mall.service.TransferService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/transfers")
@Api(tags = "TransferController", description = "查过户价")
public class TransferController {

    @Autowired
    private TransferService transferService;

    @ApiOperation("添加过户价记录")
    @RequestMapping(value = "/addOne", method = RequestMethod.POST)
    public CommonResult addOne(@RequestBody Transfer transfer) {
        try {
            transferService.saveNotNull(transfer);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success(null, "添加成功");
    }

    @ApiOperation("分页查询记录")
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    public CommonResult query(String number, Integer page, Integer size) {
        List<Transfer> transferIPage = null;
        try {
            transferIPage = transferService.find(number, page, size);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success(transferIPage);
    }

    @ApiOperation("删除过户价记录")
    @RequestMapping(value = "/delOne", method = RequestMethod.POST)
    public CommonResult delOne(Integer id) {
        try {
            transferService.deleteById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success("修改成功");
    }
}
